﻿using SL4_MVVM_MEF.MEFModule.Model;
using System.ComponentModel.Composition;
using Microsoft.Practices.Composite.Events;

namespace SL4_MVVM_MEF.MEFModule.Services
{
    [Export(typeof(IDataItemsService))]
    public class DataItemsService : IDataItemsService
    {
        private readonly IEventAggregator _eventAggregator;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="eventAggregator">EventAggregator instance imported via MEF</param>
        [ImportingConstructor]
        public DataItemsService(IEventAggregator eventAggregator)
        {
            _eventAggregator = eventAggregator;
        }

        /// <summary>
        /// Get Run-time DataItems
        /// </summary>
        public void GetDataItems()
        {
            //Initialize the collection

           var dataItems = new DataItems
                               {
                                   new DataItem() {Description = "Sample Data Item 1"},
                                   new DataItem() {Description = "Sample Data Item 2"}
                               };

            //Publish the DataItems
           _eventAggregator.GetEvent<DataItemsReceivedEvent>().Publish(dataItems);
        }
    }
}
